<?php

Raise::load('core.RaiseObject');
Raise::load('db.RaiseDbSqlIdentifier');

/**
 * RaiseDbSqlOrder class
 * represents a SQL ORDER BY
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.Core.DataAccess.Sql
 * @since 1.2
 */
class RaiseDbSqlOrder extends RaiseObject {

    /**
     * The field to sort order by
     * @var RaiseDbSqlIdentifier|string
     */
    private $field;

    /**
     * Specify whether the order is ASC or DESC
     * @var string
     */
    private $order;

    /**
     * Create a new RaiseDbSqlOrder
     * @param RaiseDbSqlIdentifier|string $f The field to sort order by
     * @param string $o (optional) The order, whether by ascending (ASC) or descending (DESC)
     */
    public function __construct($f, $o = null){
        $this->field($f);
        $this->order($o);
    }
    
    /**
     * Get or set the field to sort order by
     * @param RaiseDbSqlIdentifier|string $f (optional) The new field
     * @return RaiseDbSqlIdentifier|string
     */
    public function field($f = null){
        if(func_num_args() == 1){
            $this->field = $f;
        }
        return $this->field;
    }

    /**
     * Get or set whether the order is ascending or descending
     * @param string $o (optional) The new value
     * @return string
     */
    public function order($o = null){
        if(func_num_args() == 1){
            $this->order = $o;
        }
        return $this->order;
    }

    public function __toString(){
        $s = '';
        if($this->order){
            $s .= ' ' . $this->order;
        }
        return $this->field . $s;
    }

}